package DaoImpl;

import java.util.List;

import Dao.DAO;
import Dao.DepartmentDao;
import DoMain.CriteriaDepartment;
import DoMain.Department;

public class DepartmentDaoJdbcImpl extends DAO<Department> implements DepartmentDao{

	@Override
	public List<Department> getAll() {
		
		String sql="select * from department";
		
		return getForList(sql);
	}

	@Override
	public void save(Department department) {
		
		String sql="insert into department(departNo,departName)values(?,?)";
		
		update(sql,department.getDepartNo(),department.getDepartName());
		
	}

	@Override
	public void update(Department department) {

		String sql="update department set departName=? where departNo=?";
		
		update(sql,department.getDepartName(),department.getDepartNo());		
		
	}

	@Override
	public void delete(Integer departNo) {

		String sql="delete from department where departNo=?";
		
		update(sql,departNo);
		
	}

	@Override
	public long getCountWithName(String departName) {

		String sql="select count(departNo) from department where departName=?";
		
		return getForValue(sql,departName);
	}

	@Override
	public Department get(Integer departNo) {
		
		String sql="select * from department where departNo=?";
		
		return get(sql,departNo);
	}

	@Override
	public List<Department> getForListWithCriterialDepartment(CriteriaDepartment cd) {
		
		String sql="select * from department where departName like ?";
		
		return getForList(sql,cd.getDepartName());
	}

}
